/**
 * Created by icyhy on 2017/5/23.
 */
"use strict";
var builder = require("../response/rest.result.builder.js");
var clanDepositModel = require("../models/clan.deposit.js");

module.exports = {

  create : function (req, res, next) {
    var clanDepositEntity = new clanDepositModel(req.body);
    console.log(clanDepositEntity);
    clanDepositModel.create(clanDepositEntity, function(err) {
      if (err) return next(err);

      return builder.buildSuccessResultInfo(res, clanDepositEntity);
    });
  },
  getListByUser:function(req, res, next){
    var id = req.params.id || ''; //用户id
    clanDepositModel.find({
      'userId': id
    })
      .exec(function(err, records) {
        if (err) return next(err);
        if (!records) return next(new Error('not  found'));

        return builder.buildSuccessResultInfoWithData(res, records);
      });
  },
  getListByClan:function(req, res, next){
    var id = req.params.id || ''; //部落id
    clanDepositModel.find({
      'clanId': id
    })
      .exec(function(err, records) {
        if (err) return next(err);
        if (!records) return next(new Error('not  found'));

        return builder.buildSuccessResultInfoWithData(res, records);
      });
  },
  getById:function(req, res, next){
    var id = req.params.id || '';
    console.log( req.params.id);
    clanDepositModel.findOne({
      _id: id
    })
      .exec(function(err, record) {
        if (err) return next(err);
        if (!record) return next(new Error('not  found'));
        return builder.buildSuccessResultInfoWithData(res, record);
      });
  }
}
